var express = require('express');
var bodyParser = require('body-parser');
var sign = require('./sign.js');

/* GET home page. */
exports.list=function(req,res){
    var data=sign.delEmptyValue(req.body);
    sign.dataReq(req,data,req.session.apikey,'/sysmanage/protocol/list','post',function(ResData){
      if(ResData!=''){
        res.json(ResData);
      }
    })
}
exports.getUserProtocol=function(req,res){
  sign.dataReq(req,req.body,req.session.apikey,'/sysmanage/protocol/getprotocol','post',function(ResData){
      if(ResData!=''){
        res.send(ResData);
      }
  })
  
}
exports.getKtvList=function(req,res){
  sign.nullDataReq(req,req.session.apikey,'/sysmanage/protocol/getktvlist','post',function(ResData){
      if(ResData!=''){
        res.json(JSON.parse(ResData));
      }
    })
}
exports.edit = function(req,res){
  var data=req.body;
  if(req.body.kValue){
    delete data.kValue;
    delete data.company;
  }
  if(req.body.id==''){
    delete data.id;
  }else{
      data["id"]=parseInt(req.body.id);
  }
  var ktvListData = JSON.parse(req.body.ktvlist);
  data["ktvlist"]=ktvListData;
  sign.dataReq(req,data,req.session.apikey,'/sysmanage/protocol/edit','post',function(ResData){
    if(ResData!=''){
      res.send(ResData);
    }
  })

} 
exports.del = function(req,res){
  if(req.body.id){                     //pc单选
    var data={'ids':[req.body.id]}   
  }else if(req.body['id[]'].constructor == String){
    var data={'ids':[req.body['id[]']]}
  }else{
    var data={'ids':req.body['id[]']}   //移动端多选 
  }
  console.log(data);         //传入数组格式
  sign.dataReq(req,data,req.session.apikey,'/sysmanage/protocol/del',"POST",function(ResData){
        if(ResData!=""){
         res.send(ResData);
        }
    });
}
